package com.echat.business.home.controller;


import com.echat.business.home.model.SysUser;
import com.echat.business.home.service.ISysUserService;
import com.echat.business.system.service.OauthService;
import com.echat.core.constant.response.ResponseData;
import com.echat.core.utils.RestClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chentl123
 * @since 2019-04-19
 */
@Slf4j
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private RestClient restClient;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private OauthService oauthService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResponseData login(SysUser userInfo) {
        //校验
        if (userInfo == null) {
            return ResponseData.error("用户信息为空");
        }
        SysUser sysUser = userService.userValid(userInfo.getUsername(), userInfo.getPassword());
        if (sysUser == null) {
            return ResponseData.error("用户名或密码错误");
        }
        oauthService.getTokenFromUser(sysUser);
        return ResponseData.success(sysUser);
    }
}

